{% extends 'mold_log/base_iframe.html' %}
<!-- 零件订单 -->
{% block header %}
    <link rel="stylesheet" href="https://cdn.metroui.org.ua/v4.3.2/css/metro-all.min.css">
    <script type="text/template" id="qq-template">
        <div class="qq-uploader-selector qq-uploader" qq-drop-area-text="Drop files here">
            <div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
                <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                     class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
            </div>
            <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
                <span class="qq-upload-drop-area-text-selector"></span>
            </div>
            <div class="qq-upload-button-selector qq-upload-button">
                <div>选择报告文件</div>
            </div>
            <span class="qq-drop-processing-selector qq-drop-processing">
            <span>Processing dropped files...</span>
            <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
        </span>
            <ul class="qq-upload-list-selector qq-upload-list" aria-live="polite"
                aria-relevant="additions removals">
                <li>
                    <div class="qq-progress-bar-container-selector">
                        <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                             class="qq-progress-bar-selector qq-progress-bar"></div>
                    </div>
                    <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
                    <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
                    <span class="qq-upload-file-selector qq-upload-file"></span>
                    <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"
                          aria-label="Edit filename"></span>
                    <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
                    <span class="qq-upload-size-selector qq-upload-size"></span>
                    <button type="button" class="qq-btn qq-upload-cancel-selector qq-upload-cancel">Cancel
                    </button>
                    <button type="button" class="qq-btn qq-upload-retry-selector qq-upload-retry">Retry</button>
                    <button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">Delete
                    </button>
                    <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
                </li>
            </ul>

            <dialog class="qq-alert-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">Close</button>
                </div>
            </dialog>

            <dialog class="qq-confirm-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">No</button>
                    <button type="button" class="qq-ok-button-selector">Yes</button>
                </div>
            </dialog>

            <dialog class="qq-prompt-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <input type="text">
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">Cancel</button>
                    <button type="button" class="qq-ok-button-selector">Ok</button>
                </div>
            </dialog>
        </div>
    </script>
{% endblock %}
{% block content %}
    <div style="margin-top: 16px">
        <form action="{% url 'mold_log:rpt_upload' %}" id="qq-form">
            {% csrf_token %}
            <div>
                <div id="uploader"></div>
                <div class="form-group">
                    <label for="id_note"> 备注 </label>
                    <input class="form-control" type="text" name="note" id="id_note">
                </div>
                <div class="form-group">
                    <input class="form-check-input" type="text" name="md5" id="id_md5" hidden>
                </div>
                <div class="form-group">
                    <input class="form-check-input" type="text" name="pk" hidden value="{{ pk }}">
                </div>
                <button class="btn btn-success" type="submit">提交</button>
            </div>
        </form>
    </div>
    <div class="row" style="margin-top: 30px">
        <div class="col-auto">
            {% if reports %}
                <table class="table">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>版本</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for r in reports %}
                        <tr>
                            <td>{{ r.标题 }}</td>
                            <td>{{ r.版本 }}</td>
                            <td>{{ r.备注 }}</td>
                            <td><a href="/mold/rpt/{{ r.pk }}/" class="icon-download">下载</a></td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            {% endif %}
        </div>

    </div>
{% endblock %}
{% block script %}
    <script src="https://cdn.bootcss.com/blueimp-md5/2.18.0/js/md5.js"></script>
    <script src="https://cdn.metroui.org.ua/v4/js/metro.min.js"></script>
    <script>
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                // 计算md5
                //let m = $.md5($('#qq-file'))
                console.log($('#qq-file'))
            }
        });
        let uploader = new qq.FineUploader({
            //debug: true,
            element: document.getElementById("uploader"),
            request: {
                requireSuccessJson: false,
                customHeaders: {
                    "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val(),
                    "accept": "*"
                }
            },
            callbacks: {
                onComplete: function (id, name, json, xhr) {
                }
            },
        });
    </script>

{% endblock %}
